package dd.prog2.musterExercises.ws12set11_cnt_gui;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;

/**
 * Simple counter application which is realized without inner classes. The
 * application object itself listens to count button events.
 * 
 * @author Ruediger Lunde
 * 
 */
public class CounterApp1 implements ActionListener {

	private JTextField textField;
	private int value;

	/** Starts the counter application. */
	public void start() {
		JFrame frame = new JFrame("Counter V1");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		textField = new JTextField();
		textField.setFont(new Font("SansSerif", Font.BOLD, 60));
		textField.setText(Integer.toString(value));
		frame.add(textField, BorderLayout.CENTER);
		JButton countButton = new JButton("Count");
		frame.add(countButton, BorderLayout.SOUTH);
		countButton.addActionListener(this);
		frame.pack();
		frame.setVisible(true);
	}

	/** Increments the counter and shows the current value in the text field. */
	@Override
	public void actionPerformed(ActionEvent arg0) {
		value++;
		textField.setText(Integer.toString(value));
	}

	/** Creates the counter application and starts it. */
	public static void main(String[] args) {
		new CounterApp1().start();
	}
}
